/*********光标检测*********/
$("#register-form .in-box > .text").each(function(ind,pt){
	
	$(pt).blur(function(){
		
		$(pt).css({
			"border-color":"#ccc",
		})
		
	}).focusin(function(){
		
		$(pt).css({
			"border-color":"rgb(204,0,0)",
		})
		
	});
	
});

/*********正则验证**********/
/*手机号验证*/
$("#phone-number").blur(function(){
	
	var str = /^(13|15|17|18)+\d{9}$/;
	
	if(this.value == ""){
		
		$("#phone-tips").css({
			
			"display":"block",
			"background-position":"-155px -185px"
			
		}).text("请填写手机号码");
		
	}else{
		
		if(!str.test(this.value)){
			
			$("#phone-tips").css({
				
				"display":"block",
				"background-position":"-155px -185px"
			}).text("请填写有效的11位手机号码");
			
		}else{
			
			$("#phone-tips").css("display","none")
		}
		
	}
	
});

/*图片验证码*/
$("#picCode-number").blur(function(){
	
	var str = /^[a-zA-Z0-9]{5}$/;
	
	if(this.value == ""){
		
		$("#picCode-tips").css({
			
			"display":"block",
			"background-position":"-155px -185px"
			
		}).text("请填写验证码");
		
	}else{
		
		if(str.test(this.value)){
			
			$("#picCode-tips").css({
				
				"display":"block",
				"background-position":"-155px -150px"
				
			}).text(".");
			
		}else{
			
			$("#picCode-tips").css({
				
				"display":"block",
				"background-position":"-155px -185px"
				
			}).text("请填写正确的验证码");
		}
	}
	
});


/*手机验证码*/
$("#code-number").blur(function(){
	
	var str = /^\d{6}$/;
	
	if(this.value == ""){
		
		$("#code-tips").css({
			
			"display":"block",
			"background-position":"-155px -185px"
			
		}).text("请填写手机验证码");
		
	}else{
		
		if(str.test(this.value)){
			
			$("#code-tips").css({
				
				"display":"block",
				"background-position":"-155px -150px"
				
			}).text(".");
			
		}else{
			
			$("#code-tips").css({
				
				"display":"block",
				"background-position":"-155px -185px"
				
			}).text("验证码格式不正确");
		}
	}
	
});

/*密码*/
var password = "";
$("#password-phone").blur(function(){
	
	var str = /^[a-zA-Z0-9]{6,16}$/;
	
	if(this.value == ""){
		
		$("#password-tips").css({
			
			"display":"block",
			"background-position":"-155px -185px"
			
		}).text("请填写密码");
		
	}else{
		
		if(str.test(this.value)){
			
			password = this.value;
			
			$("#password-tips").css({
				
				"display":"block",
				"background-position":"-155px -150px"
				
			}).text(".");
			
		}else{
			
			$("#password-tips").css({
				
				"display":"block",
				"background-position":"-155px -185px"
				
			}).text("6-16位字母和数字的组合，不可用特殊字符");
		}
	}
	
});


/*确认密码*/
$("#regPassword-phone").blur(function(){
	
	
	if(this.value == ""){
		
		$("#re-password-tips").css({
			
			"display":"block",
			"background-position":"-155px -185px"
			
		}).text("请填写确认密码");
		
		
	}else{
		
		if(this.value == password){
			
			$("#re-password-tips").css({
			
				"display":"block",
				"background-position":"-155px -150px"
				
			}).text(".");
			
		}else{
			
			$("#re-password-tips").css({
			
				"display":"block",
				"background-position":"-155px -185px"
				
			}).text("两次填写的密码不一致");
			
		}
		
	}
	
});


/******************注册登录*****************/
/*用户信息*/
var sBtn = document.getElementById("register-btn");
var user = document.getElementById("phone-number");
var sPW = document.getElementById("password-phone");

sBtn.onclick = function(){
	
	setCookie("user",{"name":user.value,"password":sPW.value},7);
	
	window.location.href = "index.html";
}
